﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_Processor class represents the capabilities and management of the processor logical device.
    /// </summary>
    public class CIM_Processor : CIM_LogicalDevice
    {

        private Nullable<UInt16> _AddressWidth;
        private Nullable<UInt32> _CurrentClockSpeed;
        private Nullable<UInt16> _DataWidth;
        private Nullable<UInt16> _Family;
        private Nullable<UInt16> _LoadPercentage;
        private Nullable<UInt32> _MaxClockSpeed;
        private string _OtherFamilyDescription;
        private string _Role;
        private string _Stepping;
        private string _UniqueId;
        private Nullable<UInt16> _UpgradeMethod;

        /// <summary>
        /// Processor address width, in bits.
        /// </summary>
        public Nullable<UInt16> AddressWidth { get { return _AddressWidth; } }

        /// <summary>
        /// Current speed (in megahertz) of the processor.
        /// </summary>
        public Nullable<UInt32> CurrentClockSpeed { get { return _CurrentClockSpeed; } }

        /// <summary>
        /// Processor data width, in bits.
        /// </summary>
        public Nullable<UInt16> DataWidth { get { return _DataWidth; } }

        /// <summary>
        /// Processor family type.
        /// </summary>
        public Nullable<UInt16> Family { get { return _Family; } } //TODO enum

        /// <summary>
        /// Loading of the processor, averaged over the last minute, in a percentage.
        /// </summary>
        public Nullable<UInt16> LoadPercentage { get { return _LoadPercentage; } }

        /// <summary>
        /// Maximum speed (in megahertz) of the processor.
        /// </summary>
        public Nullable<UInt32> MaxClockSpeed { get { return _MaxClockSpeed; } }

        /// <summary>
        /// Description of the processor family type. This property is used when the Family property is set to 1 ("Other"). This string should be set to null when the Family property is a value other than 1.
        /// </summary>
        public string OtherFamilyDescription { get { return _OtherFamilyDescription; } }

        /// <summary>
        /// Free-form string that describes the role of the processor. For example, "Central Processor" or "Math Processor".
        /// </summary>
        public string Role { get { return _Role; } }

        /// <summary>
        /// Free-form string that indicates the revision level of the processor within the processor family.
        /// </summary>
        public string Stepping { get { return _Stepping; } }

        /// <summary>
        /// Globally unique identifier for the processor. This identifier can only be unique within a processor family.
        /// </summary>
        public string UniqueId { get { return _UniqueId; } }

        /// <summary>
        /// CPU socket information, which includes data on how to upgrade the processor (if upgrades are supported).
        /// </summary>
        public Nullable<UInt16> UpgradeMethod { get { return _UpgradeMethod; } } //TODO enum

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_Processor(ManagementBaseObject mbo)
            : base(mbo)
        {
            _AddressWidth = mbo.GetUshortValue("AddressWidth");
            _CurrentClockSpeed = mbo.GetUIntValue("CurrentClockSpeed");
            _DataWidth = mbo.GetUshortValue("DataWidth");
            _Family = mbo.GetUshortValue("Family");
            _LoadPercentage = mbo.GetUshortValue("LoadPercentage");
            _MaxClockSpeed = mbo.GetUIntValue("MaxClockSpeed");
            _OtherFamilyDescription = mbo.GetStringValue("OtherFamilyDescription");
            _Role = mbo.GetStringValue("Role");
            _Stepping = mbo.GetStringValue("Stepping");
            _UniqueId = mbo.GetStringValue("UniqueId");
            _UpgradeMethod = mbo.GetUshortValue("UpgradeMethod");
        }


    }
}
